import 'package:flutter/material.dart';
import 'package:sc1_manage_tool/ui/device_page.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int currentIndex = 0;

  Widget _buildNavigationRail() => NavigationRail(
        labelType: NavigationRailLabelType.all,
        destinations: const [
          NavigationRailDestination(
            icon: Icon(Icons.find_in_page),
            label: Text("发现设备"),
          ),
          NavigationRailDestination(
            icon: Icon(Icons.perm_media),
            label: Text("文件"),
          ),
        ],
        selectedIndex: currentIndex,
        onDestinationSelected: (index) {
          setState(() {
            currentIndex = index;
          });
        },
      );

  Widget _buildContentPage() {
    switch (currentIndex) {
      case 0:
        return DevicePage();
      case 1:
        return Text("文件");
      default:
        return Text("未知");
    }
  }

  Widget _buildBody() => Row(
        children: [
          _buildNavigationRail(),
          VerticalDivider(
            width: 1,
            thickness: 1,
            color: Colors.grey[300],
          ),
          Expanded(
              child: Center(
            child: _buildContentPage(),
          ))
        ],
      );

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, constraints) {
      return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.orange,
          title: const Text("Home"),
        ),
        body: _buildBody(),
      );
    });
  }
}
